package com.yaowk.sfp.file.server.service.base;

import com.yaowk.sfp.common.db.BaseServiceImpl;
import com.yaowk.sfp.file.server.entity.YkFile;
import com.yaowk.sfp.file.server.dao.FileDao;
import java.lang.Long;
import com.yaowk.sfp.file.server.service.IFileService;
import org.springframework.beans.factory.annotation.Autowired;
import java.lang.String;
import com.yaowk.sfp.file.api.model.FileModel;

public abstract class FileServiceBase extends BaseServiceImpl<FileModel, YkFile, Long> implements IFileService {

	@Autowired
	private FileDao dao;

	@Override protected FileDao getDao() {
	return dao;
	}

	@Override
	public FileModel entity2Model(YkFile entity) {
		FileModel model = null;
		if(isNotEmpty(entity)){
			model = new FileModel();
			model.setId(entity.getId());
			model.setName(entity.getName());
			model.setType(entity.getType());
			model.setFile(entity.getFile());
			model.setSize(entity.getSize());
			model.setMd5(entity.getMd5());
		}
		return model;
	}

	@Override
	public YkFile model2Entity(FileModel model) {
		YkFile entity = null;
		if(isNotEmpty(model)){
			entity = new YkFile();
			entity.setId(model.getId());
			entity.setName(model.getName());
			entity.setType(model.getType());
			entity.setFile(model.getFile());
			entity.setSize(model.getSize());
			entity.setMd5(model.getMd5());
		}
		return entity;
	}

	@Override
	public YkFile updateParams(FileModel model) {
		YkFile entity = dao.findOne(model.getId());
		if(isNotEmpty(model.getName()))
			entity.setName(model.getName());
		if(isNotEmpty(model.getType()))
			entity.setType(model.getType());
		if(isNotEmpty(model.getFile()))
			entity.setFile(model.getFile());
		if(isNotEmpty(model.getSize()))
			entity.setSize(model.getSize());
		if(isNotEmpty(model.getMd5()))
			entity.setMd5(model.getMd5());
		return entity;
	}


}